/*
 *  remove
 *  Removes an item from another
 */

objx.requires("objx.is", "objx.remove")
	.requires("objx.each", "objx.remove")
	.requires("objx.type", "objx.remove");

objx.fn.remove = function() {
	
	if (arguments.length == 1) {
		
		var 
			itemToRemove = arguments[0],
			obj = this.obj()
		;
		
		switch (this.type()) {
			case "array":
				
				var removeAtIndex = -1;
				obj = this.type("array").obj();
				
				this.each(function(item, index){
					
					if (obj[index] == itemToRemove) {
						removeAtIndex = index;
						return false;
					}
					
				});
				
				if (removeAtIndex > -1) {
					obj.splice(removeAtIndex, 1);
				}
				
				break;
			case "string":
				
				itemToRemove = objx(itemToRemove).type("string").obj();
				
				while (obj.indexOf(itemToRemove) > -1) {
					obj = obj.replace(itemToRemove, "");
				}
				
				// save it
				this.obj(obj);
				
				break;
			default:
				
				objx.error("objx.remove", "remove() doesn't know how to remove from " + this.type() + " objects.");
				
				break;
		}
		
	} else {
		
		objx(arguments).each(objx.bind(function(item){
			this.remove(item);
		}, this));
		
	}
	
	return this;
	
};

objx.provides("objx.remove");